// import $api from '@/api/api.js'
export default {
	// 全局提示
	isShowtost(msg){
		uni.showToast({
			title:msg,
			icon:"none"
		})
	},
	// 后退
	goBack(){
		uni.navigateBack({delta: 1})
	},
	// 跳转页面
	goPage(ispath){
		console.log("跳转页面",ispath);
		uni.navigateTo({
			url:ispath
		})
	},
	// 返回首页
	goIndex(){
		uni.switchTab({
			url:"/pages/tabbar/home/home"
		})
	},
	// 获取缓存里面所有的数据
	getAllStorage(){
		const storageInfo = uni.getStorageInfoSync();
		storageInfo.keys.forEach(key => {
		    const value = uni.getStorageSync(key);
		    console.log("缓存里面的数据：" + key + ': ' + value);
		});
	},
	// 查看短剧详情
	goVideoInfo(id) {
		uni.navigateTo({
			url: "/pages/videoPlay/videoPlay?id=" + id
		})
	},
	// 添加历史
	addHistory(videoItem){
		let historyList=uni.getStorageSync('history')
		if(historyList){
			let isflag=historyList.some(item=>item.id==videoItem.id)
			if(!isflag){
				console.log("如果不包含这个视频就存起来");
				historyList.unshift(videoItem)
				uni.setStorageSync('history',historyList)
			}
			console.log('播放视频是否包含这个视频',isflag);
		}else{
			console.log("如果还没有历史记录开始创建缓存");
			let historyArr=[]
			historyArr.unshift(videoItem)
			uni.setStorageSync('history',historyArr)
			console.log("获取缓存里面的历史记录",uni.getStorageSync('history'));
		}
	},
	// 记录播放时间
	recordTime(videoItem){
		let historyList=uni.getStorageSync('history')
		if(historyList){
			if(videoItem.number>=historyList[index].number){
				let index = historyList.indexOf(historyList.find(item => item.id == videoItem.id));
				historyList[index].timeDetail=videoItem.timeDetail;
				historyList[index].number=videoItem.number;
				uni.setStorageSync('history',historyList)
			}
		}
	},
	// 以往----------------------------
	goLogin() {
		uni.showModal({
			title: '提示',
			content: "该页面为游客预览页面，登录后才能正常使用",
			confirmText: '登录',
			success: function(res) {
				if (res.confirm) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
			}
		});
	},
	goLogins() {
		uni.showModal({
			title: '提示',
			content: "该功能登录后才能正常使用",
			confirmText: '登录',
			success: function(res) {
				if (res.confirm) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
			}
		});
	},
	goLoginText(text) {
		uni.showModal({
			title: '提示',
			content: text,
			confirmText: '登录',
			success: function(res) {
				if (res.confirm) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
			}
		});
	},
	goVip() {
		uni.showModal({
			title: '提示',
			content: '当前内容只对会员开放，请前去开通会员！',
			success: function(res) {
				if (res.confirm) {
					uni.navigateTo({
						url: "/pages/vip/vip"
					})
				} else if (res.cancel) {
					console.log('用户点击取消');
				}
			}
		});
	},
	goVipText(text) {
		uni.showModal({
			title: '提示',
			content: text,
			success: function(res) {
				if (res.confirm) {
					uni.navigateTo({
						url: "/pages/vip/vip"
					})
				} else if (res.cancel) {
					console.log('用户点击取消');
				}
			}
		});
	},
}